/** <a href="http://www.cpupk.com/decompiler">Eclipse Class Decompiler</a> plugin, Copyright (c) 2017 Chen Chao. **/
package com.minierp.controller;

import com.github.junrar.Archive;
import com.github.junrar.rarfile.FileHeader;
import com.minierp.bean.BusinessBillBean;
import com.minierp.bean.UserBean;
import com.minierp.dao.AccessoryDao;
import com.minierp.dao.AdjustBillDao;
import com.minierp.dao.BankAccountBalanceDao;
import com.minierp.dao.BankAccountDao;
import com.minierp.dao.BankAccountDetailDao;
import com.minierp.dao.BusinessBillDao;
import com.minierp.dao.BusinessBillItemDao;
import com.minierp.dao.CodeRuleDao;
import com.minierp.dao.CooperBillItemDao;
import com.minierp.dao.DepartmentDao;
import com.minierp.dao.EstPriceDao;
import com.minierp.dao.EstablishmentContactDao;
import com.minierp.dao.EstablishmentDao;
import com.minierp.dao.FeeBillDao;
import com.minierp.dao.FinanceDetailDao;
import com.minierp.dao.IdGenerator;
import com.minierp.dao.MakeTypeDao;
import com.minierp.dao.OutputDao;
import com.minierp.dao.PayModeDao;
import com.minierp.dao.ReceiveBillDao;
import com.minierp.dao.SerialNumberDao;
import com.minierp.dao.SmsAlertDao;
import com.minierp.dao.StockDao;
import com.minierp.dao.WorkCenterDao;
import com.minierp.dao.WorkProcessDao;
import com.minierp.err.NotAllowException;
import com.minierp.err.PermissionDennyException;
import com.minierp.helper.EncBusinessBillFormCtrHelper;
import com.minierp.helper.EncCommonHelper;
import com.minierp.helper.PageHelper;
import com.minierp.model.Accessory;
import com.minierp.model.BusinessBill;
import com.minierp.model.BusinessBillExt;
import com.minierp.model.CodeRule;
import com.minierp.model.EnterpriseInfo;
import com.minierp.model.EstPrice;
import com.minierp.model.Establishment;
import com.minierp.model.EstablishmentLevel;
import com.minierp.model.MakeType;
import com.minierp.model.SmsAlert;
import com.minierp.model.Staffer;
import com.minierp.model.TallySet;
import com.minierp.service.BusinessBillService;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.zip.CZipInputStream;
import java.util.zip.ZipEntry;
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.metadata.IIOMetadata;
import javax.imageio.stream.ImageInputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;
import org.springframework.dao.CannotAcquireLockException;
import org.springframework.util.FileCopyUtils;
import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;
import org.springframework.web.servlet.view.RedirectView;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

public class BusinessBillFormCtr extends SimpleFormController {
	private String costFormView;
	private String simpleFormView;
	private BankAccountDao bankAccountDao;
	private DepartmentDao departmentDao;
	private BusinessBillItemDao businessBillItemDao;
	private BusinessBillDao businessBillDao;
	private CodeRuleDao codeRuleDao;
	private SerialNumberDao serialNumberDao;
	private AccessoryDao accessoryDao;
	private EstablishmentContactDao establishmentContactDao;
	private MakeTypeDao makeTypeDao;
	private ReceiveBillDao receiveBillDao;
	private AdjustBillDao adjustBillDao;
	private BankAccountBalanceDao bankAccountBalanceDao;
	private BankAccountDetailDao bankAccountDetailDao;
	private PayModeDao payModeDao;
	private CooperBillItemDao cooperBillItemDao;
	private FeeBillDao feeBillDao;
	private StockDao stockDao;
	private FinanceDetailDao financeDetailDao;
	private WorkCenterDao workCenterDao;
	private WorkProcessDao workProcessDao;
	private EstablishmentDao establishmentDao;
	private OutputDao outputDao;
	private EstPriceDao estPriceDao;
	private SmsAlertDao smsAlertDao;
	private IdGenerator idGenerator;
	private BusinessBillService businessBillService;
	private DataSource dataSource;

	public SmsAlertDao getSmsAlertDao() {
		return this.smsAlertDao;
	}

	public void setSmsAlertDao(SmsAlertDao smsAlertDao) {
		this.smsAlertDao = smsAlertDao;
	}

	public WorkProcessDao getWorkProcessDao() {
		return this.workProcessDao;
	}

	public void setWorkProcessDao(WorkProcessDao workProcessDao) {
		this.workProcessDao = workProcessDao;
	}

	public String getCostFormView() {
		return this.costFormView;
	}

	public void setCostFormView(String costFormView) {
		this.costFormView = costFormView;
	}

	public String getSimpleFormView() {
		return this.simpleFormView;
	}

	public void setSimpleFormView(String simpleFormView) {
		this.simpleFormView = simpleFormView;
	}

	protected ModelAndView handleRequestInternal(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String templateId = request.getParameter("template_id");
		if (templateId != null && !templateId.equals("")
				&& EncCommonHelper.checkPurePrivilege(request, "NO_BUSI_COST")) {
			this.setFormView(this.simpleFormView);
		} else {
			this.setFormView(this.costFormView);
		}

		return super.handleRequestInternal(request, response);
	}

	protected Map referenceData(HttpServletRequest request) throws Exception {
		HashMap refData = new HashMap();
		String id = request.getParameter("id");
		if (id == null) {
			id = "";
		}

		refData.put("id", id);
		String editType = request.getParameter("edit_type");
		refData.put("editType", editType);
		refData.put("departmentList", this.departmentDao.getList(true));
		List baList = this.bankAccountDao.getList("", "");
		EnterpriseInfo ent = EncCommonHelper.getEnterpriseInfo(request);
		UserBean ub = EncCommonHelper.getCurrentUserAccount(request);
		long dfTsId = 0L;
		long specId = 0L;
		if (id != null && !id.equals("")) {
			BusinessBill bb = (BusinessBill) this.businessBillDao.get(
					BusinessBill.class, Long.parseLong(id));
			specId = bb.getBankAccountId();
			dfTsId = bb.getTallySetId();
		} else {
			dfTsId = ub.getUser().getDfTsId();
		}

		refData.put("bankAccountList",
				PageHelper.parseBaList(baList, ent, ub, dfTsId, specId));
		refData.put("payModeList", this.payModeDao.getList(false));
		refData.put("makeTypeList", this.makeTypeDao.getList(false));
		refData.put("workCenterList", this.workCenterDao.getList(false));
		return refData;
	}

	protected Object formBackingObject(HttpServletRequest request)
			throws Exception {
		String id = request.getParameter("id");
		CodeRule cr = this.codeRuleDao.get("BUSINESS_BILL");
		if (cr == null) {
			throw new Exception("Code rule not found for businessBill");
		} else {
			UserBean ub = EncCommonHelper.getCurrentUserAccount(request);
			EnterpriseInfo ent = EncCommonHelper.getEnterpriseInfo(request);
			BusinessBillBean form;
			Establishment est;
			EstablishmentLevel level;
			boolean canSelectContact1;
			List arg31;
			if (id != null && !id.equals("")) {
				BusinessBill arg25 = (BusinessBill) this.businessBillDao.get(
						BusinessBill.class, Long.parseLong(id));
				if (arg25 == null) {
					throw new Exception("Record not found for id:" + id);
				}

				BusinessBillExt arg26 = (BusinessBillExt) this.businessBillDao
						.get(BusinessBillExt.class, arg25.getId());
				est = (Establishment) this.businessBillDao.get(
						Establishment.class, arg25.getClientId());
				level = null;
				if (est != null && est.getEstLevelId() != 0L) {
					level = (EstablishmentLevel) this.businessBillDao.get(
							EstablishmentLevel.class, est.getEstLevelId());
				}

				TallySet arg32 = (TallySet) this.businessBillDao.get(
						TallySet.class, arg25.getTallySetId());
				arg31 = this.businessBillItemDao.getList(arg25.getId());
				canSelectContact1 = this.isCanSelectContact(est, ub, ent);
				form = EncBusinessBillFormCtrHelper.doFormBackingObjectEdit(cr,
						arg25, arg26, est, level, canSelectContact1, arg31,
						arg32);
			} else {
				String type = request.getParameter("type");
				String clientId;
				String mtType;
				Establishment arg29;
				EstablishmentLevel arg30;
				int arg35;
				if (type != null && type.equals("TEMPLATE")) {
					clientId = request.getParameter("template_id");
					BusinessBill arg28 = (BusinessBill) this.businessBillDao
							.get(BusinessBill.class, Long.parseLong(clientId));
					if (arg28 == null) {
						throw new Exception(
								"Template businessBill not found for id "
										+ clientId);
					}

					arg29 = (Establishment) this.businessBillDao.get(
							Establishment.class, arg28.getClientId());
					arg30 = null;
					if (arg29 != null && arg29.getEstLevelId() != 0L) {
						arg30 = (EstablishmentLevel) this.businessBillDao
								.get(EstablishmentLevel.class,
										arg29.getEstLevelId());
					}

					arg31 = this.businessBillItemDao.getList(arg28.getId());
					canSelectContact1 = this.isCanSelectContact(arg29, ub, ent);
					form = EncBusinessBillFormCtrHelper
							.doFormBackingObjectTemplate(request, cr, arg28,
									arg29, arg30, canSelectContact1, arg31);
					if (!this.isFormSubmission(request)) {
						String arg33 = form.getTmpCode();
						List arg34 = this.accessoryDao.getList("BUSINESS_BILL",
								arg28.getId(), (String[]) null, 0L);

						for (arg35 = 0; arg35 < arg34.size(); ++arg35) {
							Accessory arg37 = (Accessory) arg34.get(arg35);
							mtType = "";
							boolean arg40 = false;
							if (arg37.getFileName() != null
									&& !arg37.getFileName().equals("")) {
								String a = arg37.getFileName();
								String arg42 = EncCommonHelper.getExtendName(a);
								String uploadPath = EncCommonHelper
										.getUploadVirtualPath(this
												.getServletContext());
								String realPath = this.getServletContext()
										.getRealPath(uploadPath);
								String fileName = form.getBusinessBill()
										.getCreaterId()
										+ "_"
										+ System.currentTimeMillis()
										+ "_"
										+ arg35 + "." + arg42;
								File tf = new File(this.getServletContext()
										.getRealPath("/")
										+ System.getProperty("file.separator")
										+ a);
								if (tf.exists() && tf.isFile()) {
									FileCopyUtils
											.copy(tf,
													new File(
															realPath
																	+ System.getProperty("file.separator")
																	+ fileName));
									mtType = uploadPath + fileName;
									arg40 = true;
								}
							} else if (arg37.getCustomPath() != null
									&& !arg37.getCustomPath().equals("")) {
								arg40 = true;
							}

							if (arg40) {
								Accessory arg41 = new Accessory();
								arg41.setAgentType(arg37.getAgentType());
								arg41.setCreaterId(form.getBusinessBill()
										.getCreaterId());
								arg41.setCreaterName(form.getBusinessBill()
										.getCreaterName());
								arg41.setCreateTime(new Date());
								arg41.setFileName(mtType);
								arg41.setId(this.idGenerator
										.getId(Accessory.class.getName()));
								arg41.setMark(arg37.getMark());
								arg41.setAccType(arg37.getAccType());
								arg41.setExtId(arg37.getExtId());
								arg41.setCustomPath(arg37.getCustomPath());
								arg41.setTmpCode(arg33);
								arg41.setSourceName(arg37.getSourceName());
								this.accessoryDao.save(arg41);
							}
						}
					}
				} else if (type != null && type.equals("FILE")) {
					clientId = request.getParameter("client_id");
					String arg27 = request.getParameter("rem_fn");
					arg29 = (Establishment) this.businessBillDao.get(
							Establishment.class, Long.parseLong(clientId));
					arg30 = null;
					arg31 = null;
					canSelectContact1 = this.isCanSelectContact(arg29, ub, ent);
					if (arg29 == null) {
						throw new Exception("client not found for id:"
								+ clientId);
					}

					if (arg29.getEstLevelId() != 0L) {
						arg30 = (EstablishmentLevel) this.businessBillDao
								.get(EstablishmentLevel.class,
										arg29.getEstLevelId());
					}

					if (canSelectContact1) {
						arg31 = this.establishmentContactDao.getList(arg29
								.getId());
					}

					List mtList = this.makeTypeDao.getList(true);
					ArrayList fileArr = new ArrayList();
					if (!this.isFormSubmission(request)) {
						String i = EncCommonHelper.getUploadVirtualPath(this
								.getServletContext());
						String objs = ub.getUser().getId() + "_"
								+ System.currentTimeMillis();
						mtType = this.getServletContext().getRealPath(i) + objs;
						File wcId = new File(mtType);
						if (!wcId.isDirectory()) {
							wcId.mkdir();
						}

						this.extractFile(arg27, mtType);
						this.listFile(wcId, fileArr, i, mtList,
								Long.parseLong(clientId));
					}

					form = EncBusinessBillFormCtrHelper
							.doFormBackingObjectFile(request, cr, arg29, arg30,
									canSelectContact1, arg31, fileArr);
					if (!this.isFormSubmission(request)) {
						for (arg35 = 0; arg35 < fileArr.size(); ++arg35) {
							Object[] arg36 = (Object[]) fileArr.get(arg35);
							int arg38 = 0;
							long arg39 = 0L;
							if (arg36[5] != null) {
								arg38 = ((MakeType) arg36[5]).getType();
								arg39 = ((MakeType) arg36[5]).getWorkCenterId();
							}

							Accessory a1 = new Accessory();
							a1.setAgentType("BUSINESS_BILL");
							a1.setCreaterId(ub.getStaffer().getId());
							a1.setCreaterName(ub.getStaffer().getStafferName());
							a1.setCreateTime(new Date());
							a1.setFileName((String) arg36[1]);
							a1.setId(this.idGenerator.getId(Accessory.class
									.getName()));
							a1.setMark("");
							if (arg38 == 2) {
								a1.setAccType("COOPER");
							} else {
								a1.setAccType("DESIGN");
								a1.setExtId(arg39);
							}

							a1.setCustomPath("");
							a1.setTmpCode(form.getTmpCode());
							a1.setSourceName((String) arg36[0]);
							this.accessoryDao.save(a1);
						}
					}
				} else {
					if (!EncCommonHelper.checkPrivilege(request, "BUSI_BILL")) {
						throw new PermissionDennyException("Permission Denny");
					}

					clientId = request.getParameter("client_id");
					est = (Establishment) this.businessBillDao.get(
							Establishment.class, Long.parseLong(clientId));
					level = null;
					List contacts = null;
					boolean canSelectContact = this.isCanSelectContact(est, ub,
							ent);
					if (est == null) {
						throw new Exception("client not found for id:"
								+ clientId);
					}

					if (est.getEstLevelId() != 0L) {
						level = (EstablishmentLevel) this.businessBillDao.get(
								EstablishmentLevel.class, est.getEstLevelId());
					}

					if (canSelectContact) {
						contacts = this.establishmentContactDao.getList(est
								.getId());
					}

					form = EncBusinessBillFormCtrHelper
							.doFormBackingObjectNew(request, cr, est, level,
									canSelectContact, contacts);
				}
			}

			return form;
		}
	}

	private void extractFile(String remFn, String outPath) throws Exception {
		String separator = System.getProperty("file.separator");
		File file = new File(this.getServletContext().getRealPath(remFn));
		CZipInputStream arch;
		String tmpStr;
		if (remFn.toLowerCase().endsWith(".zip")) {
			arch = null;

			try {
				arch = new CZipInputStream(new FileInputStream(file), "GBK");

				while (true) {
					File os1;
					label856 : do {
						ZipEntry fh;
						while ((fh = arch.getNextEntry()) != null) {
							tmpStr = fh.getName();
							if (fh.isDirectory()) {
								os1 = new File(outPath + separator + tmpStr);
								continue label856;
							}

							String os = tmpStr.toLowerCase();
							if (!os.endsWith(".bat") && !os.equals(".com")
									&& !os.endsWith(".exe")
									&& !os.endsWith(".jsp")
									&& !os.endsWith(".jspx")
									&& !os.endsWith(".shtml")
									&& !os.endsWith("html")
									&& !os.endsWith(".htm")) {
								FileOutputStream f = null;

								try {
									File f1 = new File(outPath + separator
											+ tmpStr);
									if (!f1.getParentFile().exists()) {
										f1.getParentFile().mkdirs();
									}

									f = new FileOutputStream(f1);
									byte[] buf = new byte[1024];

									int len;
									while ((len = arch.read(buf)) > 0) {
										f.write(buf, 0, len);
									}

									f.flush();
									f.close();
									arch.closeEntry();
								} finally {
									if (f != null) {
										try {
											f.close();
										} catch (Exception arg59) {
											;
										}
									}

								}
							}
						}

						return;
					} while (os1.exists() && os1.isDirectory());

					os1.mkdirs();
				}
			} finally {
				if (arch != null) {
					try {
						arch.close();
					} catch (Exception arg58) {
						;
					}
				}

			}
		} else {
			arch = null;
			Archive arch1 = new Archive(file);

			try {
				while (true) {
					File tmpStr1;
					label874 : do {
						FileHeader fh1;
						while ((fh1 = arch1.nextFileHeader()) != null) {
							if (fh1.isDirectory()) {
								tmpStr1 = new File(outPath + separator
										+ fh1.getFileNameString());
								continue label874;
							}

							tmpStr = fh1.getFileNameString().toLowerCase();
							if (!tmpStr.endsWith(".bat")
									&& !tmpStr.equals(".com")
									&& !tmpStr.endsWith(".exe")
									&& !tmpStr.endsWith(".jsp")
									&& !tmpStr.endsWith(".jspx")
									&& !tmpStr.endsWith(".shtml")
									&& !tmpStr.endsWith("html")
									&& !tmpStr.endsWith(".htm")) {
								FileOutputStream os2 = null;

								try {
									File f2 = new File(outPath + separator
											+ fh1.getFileNameString());
									if (!f2.getParentFile().exists()) {
										f2.getParentFile().mkdirs();
									}

									os2 = new FileOutputStream(f2);
									arch1.extractFile(fh1, os2);
									os2.close();
								} finally {
									if (os2 != null) {
										try {
											os2.close();
										} catch (Exception arg61) {
											;
										}
									}

								}
							}
						}

						return;
					} while (tmpStr1.exists() && tmpStr1.isDirectory());

					tmpStr1.mkdirs();
				}
			} finally {
				try {
					if (arch1 != null) {
						arch1.close();
					}
				} catch (Exception arg60) {
					;
				}

			}
		}
	}

	private void listFile(File file, List arr, String parentVirPath,
			List mtList, long clientId) {
		if (file.isDirectory()) {
			File[] fileName = file.listFiles();

			for (int iis = 0; iis < fileName.length; ++iis) {
				this.listFile(fileName[iis], arr,
						parentVirPath + "/" + file.getName(), mtList, clientId);
			}
		} else {
			String arg31 = file.getName();
			ImageInputStream arg32 = null;
			int width = 0;
			int height = 0;
			float hps = 0.0F;
			float vps = 0.0F;

			try {
				arg32 = ImageIO.createImageInputStream(file);
				Iterator imgW = ImageIO.getImageReaders(arg32);
				if (imgW.hasNext()) {
					ImageReader imgH = (ImageReader) imgW.next();
					imgH.setInput(arg32, true);
					width = imgH.getWidth(0);
					height = imgH.getHeight(0);
					IIOMetadata paraStr = imgH.getImageMetadata(0);
					Element paras = (Element) paraStr
							.getAsTree("javax_imageio_1.0");
					NodeList objs = paras
							.getElementsByTagName("HorizontalPixelSize");
					if (objs != null && objs.getLength() == 1) {
						hps = Float.parseFloat(((Element) objs.item(0))
								.getAttribute("value"));
					}

					objs = paras.getElementsByTagName("VerticalPixelSize");
					if (objs != null && objs.getLength() == 1) {
						vps = Float.parseFloat(((Element) objs.item(0))
								.getAttribute("value"));
					}
				}
			} catch (Exception arg29) {
				arg29.printStackTrace();
			} finally {
				if (arg32 != null) {
					try {
						arg32.close();
					} catch (Exception arg28) {
						;
					}
				}

			}

			BigDecimal arg33 = (new BigDecimal(
					(double) ((float) width * hps / 1000.0F))).setScale(3, 4);
			BigDecimal arg34 = (new BigDecimal(
					(double) ((float) height * vps / 1000.0F))).setScale(3, 4);
			String arg35 = arg31.substring(0, arg31.lastIndexOf("."));
			String[] arg36 = arg35.split("-");
			Object[] arg37 = new Object[]{arg31, parentVirPath + "/" + arg31,
					arg33, arg34, arg36, null, null};
			long mtId = 0L;
			if (arg36.length > 1) {
				String mtName = arg36[0].trim();
				String proName = arg36[1].trim();

				for (int ep = 0; ep < mtList.size(); ++ep) {
					MakeType mt = (MakeType) mtList.get(ep);
					if (mt.getTypeName().equalsIgnoreCase(mtName)) {
						arg37[5] = mt;
						mtId = mt.getId();
						break;
					}
				}

				if (mtId != 0L) {
					EstPrice arg38 = this.estPriceDao.get("CLIENT", "EST",
							clientId, mtId, 0L, proName);
					arg37[6] = arg38;
				}
			}

			arr.add(arg37);
		}

	}

	private boolean isCanSelectContact(Establishment est, UserBean ub,
			EnterpriseInfo ent) {
		boolean canSelectContact = false;
		if (ent.getSelectContact() != null
				&& ent.getSelectContact().equals("ALL")) {
			canSelectContact = true;
		} else if (est != null && est.getManagerId() != 0L) {
			if (est.getManagerId() == ub.getStaffer().getId()) {
				canSelectContact = true;
			} else {
				Staffer s = (Staffer) this.businessBillDao.get(Staffer.class,
						est.getManagerId());
				if (s != null
						&& s.getSuperiorIdStr() != null
						&& s.getSuperiorIdStr().indexOf(
								";" + ub.getStaffer().getId() + ";") != -1) {
					canSelectContact = true;
				}
			}
		}

		return canSelectContact;
	}

	protected void onBind(HttpServletRequest request, Object command)
			throws Exception {
		BusinessBillBean form = (BusinessBillBean) command;
		EncBusinessBillFormCtrHelper.doOnBind(request, form, this.dataSource);
	}

	protected ModelAndView onSubmit(HttpServletRequest request,
			HttpServletResponse response, Object command, BindException errors)
			throws Exception {
		ModelAndView mv = new ModelAndView(this.getSuccessView());
		String id = request.getParameter("id");
		String alertMsg = "";
		BusinessBillBean form = (BusinessBillBean) command;
		BusinessBill obj = form.getBusinessBill();
		UserBean ub = EncCommonHelper.getCurrentUserAccount(request);
		boolean saBusClie = false;
		String customTxt = "";
		EnterpriseInfo ent = EncCommonHelper.getEnterpriseInfo(request);
		SmsAlert sa = this.smsAlertDao.get("BUS_CLIE");
		if (sa != null && sa.getStatus() != null && sa.getStatus().equals("Y")) {
			saBusClie = true;
			customTxt = sa.getCustomTxt();
		}

		String alertType1;
		if (id != null && !id.equals("")) {
			alertType1 = request.getParameter("edit_type");
			if (alertType1 == null) {
				alertType1 = "";
			}

			if (alertType1.equals("PRICE")) {
				if (!EncCommonHelper.checkPrivilege(request, "BUSI_EDIT_PRIC")) {
					throw new Exception("Permission deny!");
				}
			} else if (alertType1.equals("MODIFY")) {
				if (!EncCommonHelper.checkPrivilege(request, "BUSI_MODI")) {
					throw new Exception("Permission deny!");
				}
			} else if (!EncCommonHelper.checkPrivilege(request, "BUSI_BILL")) {
				throw new Exception("Permission deny!");
			}

			try {
				List flag = this.workProcessDao.getList(0L, true);
				this.businessBillService
						.txUpdate(form, ent, ub, alertType1, flag,
								this.businessBillDao, this.businessBillItemDao,
								this.receiveBillDao, this.adjustBillDao,
								this.bankAccountBalanceDao,
								this.bankAccountDetailDao,
								this.cooperBillItemDao, this.feeBillDao,
								this.stockDao, this.idGenerator,
								this.financeDetailDao, this.outputDao);
			} catch (CannotAcquireLockException arg19) {
				EncCommonHelper.setAlertMessage(request, "事务冲突故障，请重新操作！");
				return this.showForm(request, errors, this.getFormView());
			} catch (NotAllowException arg20) {
				EncCommonHelper.setAlertMessage(request, arg20.getMessage());
				return this.showForm(request, errors, this.getFormView());
			}

			alertMsg = "修改成功！";
		} else {
			try {
				Map alertType = this.businessBillService.txInsert(form, ent,
						ub, this.businessBillDao, this.businessBillItemDao,
						this.serialNumberDao, this.accessoryDao,
						this.bankAccountBalanceDao, this.cooperBillItemDao,
						this.feeBillDao, this.stockDao, this.idGenerator,
						this.outputDao);
				if (alertType.get("exam") != null) {
					try {
						if (saBusClie) {
							PageHelper.sendBusClieSms(alertType, customTxt,
									ent.getShortName(), this.businessBillDao,
									this.idGenerator);
						}
					} catch (Exception arg21) {
						arg21.printStackTrace();
					}
				}
			} catch (CannotAcquireLockException arg22) {
				EncCommonHelper.setAlertMessage(request, "事务冲突故障，请重新操作！");
				return this.showForm(request, errors, this.getFormView());
			} catch (NotAllowException arg23) {
				EncCommonHelper.setAlertMessage(request, arg23.getMessage());
				return this.showForm(request, errors, this.getFormView());
			}

			alertMsg = "增加成功！";
		}

		mv.addObject("returnValue", String.valueOf(obj.getId()));
		alertType1 = request.getParameter("alert_type");
		String flag1 = request.getParameter("continue_flag");
		String templateId = request.getParameter("template_id");
		boolean simpleForm = false;
		if (templateId != null && !templateId.equals("")
				&& EncCommonHelper.checkPurePrivilege(request, "NO_BUSI_COST")) {
			simpleForm = true;
			alertType1 = "SHOW";
		}

		if (flag1 != null && !flag1.equals("")) {
			if (!flag1.equals("CLOSE")) {
				if (flag1.equals("PRINT")) {
					String url = "/business/BusinessBillPrint.ihtm?id="
							+ obj.getId();
					if (simpleForm) {
						url = url + "&type=SIMPLE";
					}

					mv = new ModelAndView(new RedirectView(url));
				} else if (flag1.equals("NEW")) {
					mv = new ModelAndView(new RedirectView(
							"/business/BusinessBillNew.ihtm?client_id="
									+ obj.getClientId() + "&alert_type="
									+ alertType1));
				}
			}
		} else if (alertType1 == null || !alertType1.equals("NONE")) {
			EncCommonHelper.setAlertMessage(request, alertMsg);
			if (alertType1 != null && alertType1.equals("FORM")) {
				mv = new ModelAndView(new RedirectView(
						"/business/BusinessBillEdit.ihtm?id=" + obj.getId()
								+ "&alert_type=" + alertType1));
			}
		}

		mv.addObject("alertType", alertType1);
		return mv;
	}

	public IdGenerator getIdGenerator() {
		return this.idGenerator;
	}

	public void setIdGenerator(IdGenerator idGenerator) {
		this.idGenerator = idGenerator;
	}

	public BusinessBillDao getBusinessBillDao() {
		return this.businessBillDao;
	}

	public void setBusinessBillDao(BusinessBillDao businessBillDao) {
		this.businessBillDao = businessBillDao;
	}

	public CodeRuleDao getCodeRuleDao() {
		return this.codeRuleDao;
	}

	public void setCodeRuleDao(CodeRuleDao codeRuleDao) {
		this.codeRuleDao = codeRuleDao;
	}

	public SerialNumberDao getSerialNumberDao() {
		return this.serialNumberDao;
	}

	public void setSerialNumberDao(SerialNumberDao serialNumberDao) {
		this.serialNumberDao = serialNumberDao;
	}

	public BankAccountDao getBankAccountDao() {
		return this.bankAccountDao;
	}

	public void setBankAccountDao(BankAccountDao bankAccountDao) {
		this.bankAccountDao = bankAccountDao;
	}

	public BusinessBillItemDao getBusinessBillItemDao() {
		return this.businessBillItemDao;
	}

	public void setBusinessBillItemDao(BusinessBillItemDao businessBillItemDao) {
		this.businessBillItemDao = businessBillItemDao;
	}

	public DepartmentDao getDepartmentDao() {
		return this.departmentDao;
	}

	public void setDepartmentDao(DepartmentDao departmentDao) {
		this.departmentDao = departmentDao;
	}

	public AccessoryDao getAccessoryDao() {
		return this.accessoryDao;
	}

	public void setAccessoryDao(AccessoryDao accessoryDao) {
		this.accessoryDao = accessoryDao;
	}

	public EstablishmentContactDao getEstablishmentContactDao() {
		return this.establishmentContactDao;
	}

	public void setEstablishmentContactDao(
			EstablishmentContactDao establishmentContactDao) {
		this.establishmentContactDao = establishmentContactDao;
	}

	public MakeTypeDao getMakeTypeDao() {
		return this.makeTypeDao;
	}

	public void setMakeTypeDao(MakeTypeDao makeTypeDao) {
		this.makeTypeDao = makeTypeDao;
	}

	public BusinessBillService getBusinessBillService() {
		return this.businessBillService;
	}

	public void setBusinessBillService(BusinessBillService businessBillService) {
		this.businessBillService = businessBillService;
	}

	public ReceiveBillDao getReceiveBillDao() {
		return this.receiveBillDao;
	}

	public void setReceiveBillDao(ReceiveBillDao receiveBillDao) {
		this.receiveBillDao = receiveBillDao;
	}

	public AdjustBillDao getAdjustBillDao() {
		return this.adjustBillDao;
	}

	public void setAdjustBillDao(AdjustBillDao adjustBillDao) {
		this.adjustBillDao = adjustBillDao;
	}

	public DataSource getDataSource() {
		return this.dataSource;
	}

	public void setDataSource(DataSource dataSource) {
		this.dataSource = dataSource;
	}

	public BankAccountBalanceDao getBankAccountBalanceDao() {
		return this.bankAccountBalanceDao;
	}

	public void setBankAccountBalanceDao(
			BankAccountBalanceDao bankAccountBalanceDao) {
		this.bankAccountBalanceDao = bankAccountBalanceDao;
	}

	public BankAccountDetailDao getBankAccountDetailDao() {
		return this.bankAccountDetailDao;
	}

	public void setBankAccountDetailDao(
			BankAccountDetailDao bankAccountDetailDao) {
		this.bankAccountDetailDao = bankAccountDetailDao;
	}

	public PayModeDao getPayModeDao() {
		return this.payModeDao;
	}

	public void setPayModeDao(PayModeDao payModeDao) {
		this.payModeDao = payModeDao;
	}

	public CooperBillItemDao getCooperBillItemDao() {
		return this.cooperBillItemDao;
	}

	public void setCooperBillItemDao(CooperBillItemDao cooperBillItemDao) {
		this.cooperBillItemDao = cooperBillItemDao;
	}

	public FeeBillDao getFeeBillDao() {
		return this.feeBillDao;
	}

	public void setFeeBillDao(FeeBillDao feeBillDao) {
		this.feeBillDao = feeBillDao;
	}

	public StockDao getStockDao() {
		return this.stockDao;
	}

	public void setStockDao(StockDao stockDao) {
		this.stockDao = stockDao;
	}

	public FinanceDetailDao getFinanceDetailDao() {
		return this.financeDetailDao;
	}

	public void setFinanceDetailDao(FinanceDetailDao financeDetailDao) {
		this.financeDetailDao = financeDetailDao;
	}

	public WorkCenterDao getWorkCenterDao() {
		return this.workCenterDao;
	}

	public void setWorkCenterDao(WorkCenterDao workCenterDao) {
		this.workCenterDao = workCenterDao;
	}

	public EstablishmentDao getEstablishmentDao() {
		return this.establishmentDao;
	}

	public void setEstablishmentDao(EstablishmentDao establishmentDao) {
		this.establishmentDao = establishmentDao;
	}

	public OutputDao getOutputDao() {
		return this.outputDao;
	}

	public void setOutputDao(OutputDao outputDao) {
		this.outputDao = outputDao;
	}

	public EstPriceDao getEstPriceDao() {
		return this.estPriceDao;
	}

	public void setEstPriceDao(EstPriceDao estPriceDao) {
		this.estPriceDao = estPriceDao;
	}
}